package thread.atomic;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 计数器==>单例
 *
 * @author liweimin
 * @date 2021/4/29 16:09
 * @since
 */
public class Indicator {

    /**
     * 请求总数
     */
    private final AtomicLong requestCount = new AtomicLong(0L);

    /**
     * 成功请求数
     */
    private final AtomicLong successCount = new AtomicLong(0L);

    /**
     * 失败请求数
     */
    private final AtomicLong failureCount = new AtomicLong(0L);

    private static final Indicator instance = new Indicator();

    private Indicator() {
    }

    public static Indicator getInstance() {
        return instance;
    }

    public void newRequest() {
        requestCount.incrementAndGet();
    }

    public void handleSuccess() {
        successCount.incrementAndGet();
    }

    public void handleFailure() {
        failureCount.incrementAndGet();
    }

    public Long getRequestCount() {
        return requestCount.get();
    }

    public Long getSuccessCount() {
        return successCount.get();
    }

    public Long getFailureCount() {
        return failureCount.get();
    }
}
